// void, Obj This, point pt
{
	Hero this;
	Unit u, uEnemy;
	int exp, j, i;
	int e_armor, armor, lv; 
	int e_lv, damage, power;
	
	Sleep(rand(10)+20);
	this = This.AsHero();
	if(!.IsValid) return;
	if(.DistTo(pt) >= 3000) return;

	if(.stamina >= cmdcost_stamina)
		.SetStamina(.stamina - cmdcost_stamina);
	else return;
	
	.AddCommand(true, "engage");
	
	for(j = 0; j<10; j+=1){
				  
		Sleep(20);
		.PlaySound("data/Sound Entities/CAVALRYATACKCAMEL.XML");
	}   
	{		
		.FormSetupAndMoveTo (pt, 0, 0, true);
		
		// freeze patch
		if(!.HasPath()){
			Sleep(985);
			return;
		}
			
		while(.HasPath()){
			
			if(.EnemiesInSight){
				.FormKeepMoving (400);
				
				.army.ClearDead;
				for(i=0; i<.army.count; i+=1){
						 
					u = .army[i].AsUnit;
					
					if(u.IsValid){
					
						u.PlaySound("data/Sound Entities/VOICECHARGE.XML"); 
									
						if(u.stamina >= 6){
							
							uEnemy = u.BestTargetInRange( u.posRH, 60 ).AsUnit;
							if (uEnemy.IsAlive){
								if(u.IsValidTarget(uEnemy)){
									if(!uEnemy.AsHero.IsValid){
										if(uEnemy.IsVisible){
											if(!uEnemy.IsHeirOf("Sentry")){
												
												armor = u.armor_slash;
												lv = u.level;
												e_armor = uEnemy.armor_slash;
												e_lv = uEnemy.level;
												
												damage = 50+(u.health/4)+armor+lv-e_armor-e_lv;
												
												if(uEnemy.command == "stand_position"){
													if(uEnemy.hero.IsValid){
														if(uEnemy.hero.formation == "Square"){
															if(damage > 0)
																damage = damage/2;
														}
													}
												}
												if(uEnemy.HasSpecial(deflection)){
													if( uEnemy.command == "retreat" ||
														uEnemy.command == "retreat_notai" ||
														uEnemy.command == "retreat_bld_notai" ){
														if(uEnemy.Damage(damage)) exp+=1;
													} else {
														if(uEnemy.stamina > 0){
															uEnemy.SetStamina(0);
														} else if(uEnemy.stamina == 0){
															if(uEnemy.Damage(damage)) exp+=1;
														}
														if(uEnemy.hero.IsValid){
															power = EnvReadInt(uEnemy.hero.player, "PikedCount/"+uEnemy.hero.name);
															power = power+(uEnemy.armor_slash*4);
															u.Damage(power);
														}
													}
												} else {
													if(uEnemy.Damage(damage)) exp+=1;
												}
												if(u.stamina >= 6)
													u.SetStamina(u.stamina - 6);
												else
													u.SetStamina(0);
											}
										}
									}
								}
							}
						}
						CreateFeedback("Charge", u);
					}
					Sleep(5);
				}
			} else { .FormKeepMoving (800); }
		}
		if(exp > 0)
			.SetExperience(.experience + exp/20);
	
	}

}
